package cn.matezk.lianlian.utils;

import cn.hutool.core.util.ObjectUtil;

public class ObjectUtils extends ObjectUtil {
    public static String sub(String text, int length) {
        if (isEmpty(text))   return "";
        if (text.length() <= length)    return text;
        return text.substring(0, length);
    }

    public static String amount(int amount) {
        String text = String.valueOf(amount / 100.0);
        if (text.endsWith(".0"))
            return text.substring(0, text.indexOf("."));
        return text;
    }

    public static String createVariable(String key) {
        return "$".concat("{").concat(key).concat("}");
    }

    public static String ifNull(String value, String defaultValue) {
        return isNull(value) ? defaultValue : value;
    }
}
